package com.pengji.rcp.plugin.view;

import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import com.pengji.rcp.plugin.domain.TreeObject;
import com.pengji.rcp.plugin.domain.TreeParent;
import com.pengji.rcp.plugin.provider.ViewContentProvider;
import com.pengji.rcp.plugin.provider.ViewLabelProvider;

public class NavigationView extends ViewPart {
	
	private TreeViewer viewer;

	private TreeObject createDummyModel() {
		TreeObject to1 = new TreeObject("Inbox");
		TreeObject to2 = new TreeObject("Drafts");
		TreeObject to3 = new TreeObject("Sent");
		TreeParent p1 = new TreeParent("me@this.com");
		p1.addChild(to1);
		p1.addChild(to2);
		p1.addChild(to3);

		TreeObject to4 = new TreeObject("Inbox");
		TreeParent p2 = new TreeParent("other@aol.com");
		p2.addChild(to4);

		TreeParent root = new TreeParent("");
		root.addChild(p1);
		root.addChild(p2);
		return root;
	}

	@Override
	public void createPartControl(Composite parent) {
		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		viewer.setContentProvider(new ViewContentProvider());
		viewer.setLabelProvider(new ViewLabelProvider());
		viewer.setInput(createDummyModel());
	}

	@Override
	public void setFocus() {
		viewer.getControl().setFocus();
	}
}